#include "chat.h"
#include "protocol.h"
#include "ui_chat.h"
#include "client.h"

Chat::Chat(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Chat)
{
    ui->setupUi(this);
    setAttribute(Qt::WA_QuitOnClose, false);
}

Chat::~Chat()
{
    delete ui;
}

void Chat::updateShowContent(QString strMsg)
{
    ui->showContent_TE->append(strMsg);
}

void Chat::setChatName(QString strName)
{
    this->m_strChatName = strName;
    this->setWindowTitle(strName);
}

void Chat::on_send_PB_clicked()
{
    QString strMsg = ui->input_LE->text();
    ui->input_LE->clear();
    PDU* pdu = mkPDU(ENUM_MSG_TYPE_CHAT_REQUEST, strMsg.toStdString().size());
    memcpy(pdu->caData, Client::getInstance().m_strLoginName.toStdString().c_str(), 32);
    memcpy(pdu->caData + 32, m_strChatName.toStdString().c_str(), 32);
    memcpy(pdu->caMsg, strMsg.toStdString().c_str(), pdu->uiMsgLen);
    Client::getInstance().sendMsg(pdu);
}
